<? $worker = select_lines_all_items($table_Prefix."employee","nid desc","status = '在职'","0")?>

<? $quanxian=explode(",",$_SESSION['quanxian']);?>


<?

if(in_array("admin",$quanxian))
{
    $workerid = $_REQUEST['workerid'] ;
}

?>

<?
if(!$workerid)
{
    $workerid = $_SESSION['nid'];
}
?>









<?
//这部分是未完成的项目的预想提成。
$case_list_not_done = select_lines_all_items($table_Prefix . "case", "nid desc", "
(agent     ='" . $workerid . "' or
respon    ='" . $workerid . "' or
dist_sales     ='" . $workerid . "' or
sales     ='" . $workerid . "' or
service   ='" . $workerid . "' or
designer  ='" . $workerid . "' or
programer ='" . $workerid . "' or
operator ='" . $workerid . "' or
editor    ='" . $workerid . "') and startdate > '2018-12-31 23:59:59' and status = '进行中'", "");


$case_id_list_not_done=transform_2darray_in_1darray_number_as_key($case_list_not_done,"nid");

$case_id_list_srt_not_done=implode(",", $case_id_list_not_done);

$bonus_list_not_done = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt_not_done.")", "0");

foreach($bonus_list_not_done as $k => $v)
{
$case_bonus_not_done[$v['caseid']]=$v;
}






//获取本页用到的单位的名字
$unit_nid_list_not_done=transform_2darray_in_1darray_with_new_key($case_list_not_done,"nid","unit");
$unit_nid_list_str_not_done=implode("','",$unit_nid_list_not_done);
$unit_list_not_done=select_lines_all_items($table_Prefix."unit","","nid in ('".$unit_nid_list_str_not_done."')","");
$unit_name_list_not_done=transform_2darray_in_1darray_with_new_key($unit_list_not_done,"nid","name");



?>


<fieldset class="layui-elem-field layui-field-title">
    <legend>绩效预计 </legend>
</fieldset>

<div class="shrinker" >根据个人参与的项目所在的位置评分。然后根据项目的权重来计算奖励分。</div>



<div>
    <?
    if(in_array("admin",$quanxian))
    {
        for($i=0;$i<count($worker);$i++){?>
        <a href="/controller/extender/dashboard/view/index.php?workerid=<? echo $worker[$i]['nid'] ?>" style="<? if($worker[$i]['nid']=="$workerid"){echo "text-decoration:underline";}?>" ><? echo $worker[$i]['name']?></a>
        <?;}
    } ?>


</div>





<div class="statistics-box layui-form">


    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="80">

                <col width="220">
                <col width="220">

                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>

                <th>时间</th>
                <th>单位</th>
                <th>项目</th>
                <th>签约超时</th>
                <th>完工超时</th>
                <th>收款超时</th>
                <th>项目金额</th>
                <th>业务</th>
                <th>派单业务</th>
                <th>责任人</th>
                <th>跟单</th>
                <th>设计师</th>
                <th>程序员</th>
                <th>编辑</th>
                <th>运营</th>
            </tr>
            </thead>
            <tbody>


            <? for($i=0;$i<count($case_list_not_done);$i++){?>
                <tr>
                    <td>未完成</td>
                    <td> <a href="../../unit/view/detail-statistic.php?&nid=<?echo $case_list_not_done[$i]['unit']?>&nav-itemed=unit" target="_blank"><?echo $unit_name_list_not_done[$case_list_not_done[$i]['unit']]?> </a> </td>
                    <td><a href="../../case/view/detail-info.php?&nid=<?echo $case_list_not_done[$i]['nid']?>&nav-itemed=case"  target="_blank"><?echo $case_list_not_done[$i]['name']?></a> </td>

                    <? if((!$case_list_not_done[$i]['startdate']) or ($case_list_not_done[$i]['startdate']=="0000-00-00 00:00:00")) {$case_list_not_done[$i]['startdate']=date("Y-m-d h:i:s");}?>
                    <? if((!$case_list_not_done[$i]['enddate']) or ($case_list_not_done[$i]['enddate']=="0000-00-00 00:00:00"))  {$case_list_not_done[$i]['enddate']=date("Y-m-d h:i:s");}?>
                    <? if((!$case_list_not_done[$i]['paydate']) or ($case_list_not_done[$i]['paydate']=="0000-00-00 00:00:00"))  {$case_list_not_done[$i]['paydate']=date("Y-m-d h:i:s");}?>

                    <td> <?if(($case_list_not_done[$i]['expect_startdate']) and ($case_list_not_done[$i]['expect_startdate']!="0000-00-00 00:00:00")){echo count_days($case_list_not_done[$i]['expect_startdate'],$case_list_not_done[$i]['startdate']);}?></td>
                    <td> <?if(($case_list_not_done[$i]['expect_enddate']) and ($case_list_not_done[$i]['expect_enddate']!="0000-00-00 00:00:00")){echo count_days($case_list_not_done[$i]['expect_enddate'],$case_list_not_done[$i]['enddate']);}?></td>
                    <td> <?if(($case_list_not_done[$i]['expect_paydate']) and ($case_list_not_done[$i]['expect_paydate']!="0000-00-00 00:00:00")){echo count_days($case_list_not_done[$i]['expect_paydate'],$case_list_not_done[$i]['paydate']);}?></td>



                    <td><?echo $case_list_not_done[$i]['sum']?></td>

							
							
                    <td>
<!--                        --><?//echo "w".$workerid?>
<!--                        --><?//echo "case_list_not_done[i]['nid']".$case_list_not_done[$i]['nid']?>
<!--                        --><?//echo "sales".$case_bonus_not_done[$case_list_not_done[$i]['nid']]['sales']?>
<!--    -->
<!--                        --><?// print_r2($case_bonus_not_done);?>
<!--    -->
<!--                        --><?//exit;?>
                        
                        <?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['sales']==$workerid)
                        {echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['sales_bonus'];
                            $sum_sales_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['sales_bonus'];}?>
                    </td>
                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['dist_sales']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['dist_sales_bonus'];
                            $sum_dist_sales_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['dist_sales_bonus'];}?></td>

                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['respon']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['respon_bonus'];
                            $sum_respon_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['respon_bonus'];}?></td>


                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['service']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['service_bonus'];
                            $sum_service_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['service_bonus'];}?></td></td>
                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['designer']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['designer_bonus'];
                            $sum_designer_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['designer_bonus'];}?></td>
                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['programer']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['programer_bonus'];
                            $sum_programer_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['programer_bonus'];}?></td>
                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['editor']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['editor_bonus'];
                            $sum_editor_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['editor_bonus'];}?></td>
                    <td><?if($case_bonus_not_done[$case_list_not_done[$i]['nid']]['operator']==$workerid){echo $case_bonus_not_done[$case_list_not_done[$i]['nid']]['operator_bonus'];
                            $sum_operator_not_done[]=$case_bonus_not_done[$case_list_not_done[$i]['nid']]['operator_bonus'];}?></td>
                </tr>
                <?;}?>






            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td> </td>
                <td><?echo array_sum($sum_agent_not_done);?> </td>
                <td><?echo array_sum($sum_sales_not_done);?> </td>
                <td><?echo array_sum($sum_dist_sales_not_done);?> </td>
                <td><?echo array_sum($sum_respon_not_done);?> </td>
                <td><?echo array_sum($sum_service_not_done);?> </td>
                <td><?echo array_sum($sum_designer_not_done);?> </td>
                <td><?echo array_sum($sum_programer_not_done);?> </td>
                <td><?echo array_sum($sum_editor_not_done);?> </td>
                <td><?echo array_sum($sum_operator_not_done);?> </td>
            </tr>
            <tr>
                <td colspan="17" style="text-align: center">合计<?echo array_sum($sum_agent_not_done)+array_sum($sum_sales_not_done)+array_sum($sum_dist_sales_not_done)+array_sum($sum_respon_not_done)+array_sum($sum_service_not_done)+array_sum($sum_designer_not_done)+array_sum($sum_programer_not_done)+array_sum($sum_editor_not_done);?></td>
            </tr>


            </tbody>
        </table>
    </div>
</div>



















<fieldset class="layui-elem-field layui-field-title">
    <legend>个人绩效：<? echo date("Y-m")?> </legend>
    <div class="shrinker" >此绩效按照项目的结算日期为准</div>
</fieldset>



<?
//项目提成计算方法，只在2019年开始的项目有得计算提成。
//提成结算在付款时间的月度。
//






$case_list = select_lines_all_items($table_Prefix . "case", "nid desc", "
(agent     ='" . $workerid . "' or
respon    ='" . $workerid . "' or
sales     ='" . $workerid . "' or
dist_sales     ='" . $workerid . "' or
service   ='" . $workerid . "' or
designer  ='" . $workerid . "' or
programer ='" . $workerid . "' or
operator ='" . $workerid . "' or
editor    ='" . $workerid . "') and count_date like '".date("Y-m")."%' ", "");



$case_id_list=transform_2darray_in_1darray_number_as_key($case_list,"nid");

$case_id_list_srt=implode(",", $case_id_list);

$bonus_list = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt.")", "0");

foreach($bonus_list as $k => $v)
{
    $case_bonus[$v['caseid']]=$v;
}



//获取本页用到的单位的名字
$unit_nid_list=transform_2darray_in_1darray_with_new_key($case_list,"nid","unit");
$unit_nid_list_str=implode("','",$unit_nid_list);
$unit_list=select_lines_all_items($table_Prefix."unit","","nid in ('".$unit_nid_list_str."')","");
$unit_name_list=transform_2darray_in_1darray_with_new_key($unit_list,"nid","name");

?>
















<div class="statistics-box layui-form">


    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="60">
                <col width="120">

                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>

                <th>序号</th>
                <th>时间</th>
                <th>单位</th>
                <th>项目</th>
                <th>项目金额</th>
                <th>介绍人</th>
                <th>业务</th>
                <th>派单</th>
                <th>责任人</th>
                <th>跟单</th>
                <th>设计师</th>
                <th>程序员</th>
                <th>编辑</th>
                <th>运营</th>
            </tr>
            </thead>
            <tbody>






<? for($i=0;$i<count($case_list);$i++){?>
    <tr>
        <td><?echo $i+1?></td>
        <td><?echo substr($case_list[$i]['paydate'],0,10)?></td>
        <td> <a href="/controller/extender/unit/view/detail-statistic.php?&nid=<?echo $case_list[$i]['unit']?>&nav-itemed=unit" target="_blank"><?echo $unit_name_list[$case_list[$i]['unit']]?> </a> </td>
        <td><a href="/controller/extender/case/view/detail-edit.php?&nid=<?echo $case_list[$i]['nid']?>&nav-itemed=case"  target="_blank"><?echo $case_list[$i]['name']?></a> </td>

     
        <td><?echo $case_list[$i]['sum']?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['agent']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['agent_bonus'];
                $sum_agent[]=$case_bonus[$case_list[$i]['nid']]['agent_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['sales']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['sales_bonus'];
                $sum_sales[]=$case_bonus[$case_list[$i]['nid']]['sales_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['dist_sales']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['dist_sales_bonus'];
                $sum_dist_sales[]=$case_bonus[$case_list[$i]['nid']]['dist_sales_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['respon']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['respon_bonus'];
                $sum_respon[]=$case_bonus[$case_list[$i]['nid']]['respon_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['service']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['service_bonus'];
                $sum_service[]=$case_bonus[$case_list[$i]['nid']]['service_bonus'];}?></td></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['designer']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['designer_bonus'];
                $sum_designer[]=$case_bonus[$case_list[$i]['nid']]['designer_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['programer']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['programer_bonus'];
                $sum_programer[]=$case_bonus[$case_list[$i]['nid']]['programer_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['editor']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['editor_bonus'];
                $sum_editor[]=$case_bonus[$case_list[$i]['nid']]['editor_bonus'];}?></td>
        <td><?if($case_bonus[$case_list[$i]['nid']]['operator']==$workerid){echo $case_bonus[$case_list[$i]['nid']]['operator_bonus'];
                $sum_operator[]=$case_bonus[$case_list[$i]['nid']]['operator_bonus'];}?></td>

    </tr>
<?;}?>

 

<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td><?echo array_sum($sum_agent);?> </td>
    <td><?echo array_sum($sum_sales);?> </td>
    <td><?echo array_sum($sum_dist_sales);?> </td>
    <td><?echo array_sum($sum_respon);?> </td>
    <td><?echo array_sum($sum_service);?> </td>
    <td><?echo array_sum($sum_designer);?> </td>
    <td><?echo array_sum($sum_programer);?> </td>
    <td><?echo array_sum($sum_editor);?> </td>
    <td><?echo array_sum($sum_operator);?> </td>
</tr>
<tr>
    <td colspan="14" style="text-align: center">合计<?echo array_sum($sum_agent)+array_sum($sum_sales)+array_sum($sum_dist_sales)+array_sum($sum_respon)+array_sum($sum_service)+array_sum($sum_designer)+array_sum($sum_programer)+array_sum($sum_editor);?></td>
</tr>


            </tbody>
        </table>
    </div>
    </div>


 
<?
//项目提成计算方法，只在2019年开始的项目有得计算提成。
//提成结算在付款时间的月度。
//


//$bonus_list = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "
//(agent     ='" . $_SESSION['nid'] . "' or
//respon    ='" . $_SESSION['nid'] . "' or
//sales     ='" . $_SESSION['nid'] . "' or
//service   ='" . $_SESSION['nid'] . "' or
//designer  ='" . $_SESSION['nid'] . "' or
//programer ='" . $_SESSION['nid'] . "' or
//editor    ='" . $_SESSION['nid'] . "')  ", "0");



$last_month=date('Y-m',strtotime('midnight first day of -1 month'));


?>
<fieldset class="layui-elem-field layui-field-title">
                    <legend> 个人绩效：<? echo $last_month?> </legend>
                </fieldset>
<?
				
				
				
$case_list2 = select_lines_all_items($table_Prefix . "case", "nid desc", "
(agent     ='" . $workerid . "' or
respon    ='" . $workerid . "' or
sales     ='" . $workerid . "' or
dist_sales     ='" . $workerid . "' or
service   ='" . $workerid . "' or
designer  ='" . $workerid . "' or
programer ='" . $workerid . "' or
operator ='" . $workerid . "' or
editor    ='" . $workerid . "') and count_date like '".$last_month."%' ", "");


$case_id_list2=transform_2darray_in_1darray_number_as_key($case_list2,"nid");

$case_id_list_srt2=implode(",", $case_id_list2);

$bonus_list2 = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt2.")", "0");

foreach($bonus_list2 as $k => $v)
{
    $case_bonus2[$v['caseid']]=$v;
}




//获取本页用到的单位的名字
$unit_nid_list2=transform_2darray_in_1darray_with_new_key($case_list2,"nid","unit");
$unit_nid_list_str2=implode("','",$unit_nid_list2);
$unit_list2=select_lines_all_items($table_Prefix."unit","","nid in ('".$unit_nid_list_str2."')","");
$unit_name_list2=transform_2darray_in_1darray_with_new_key($unit_list2,"nid","name");

?>


<div class=" statistics-box layui-form">


    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="60">
                <col width="120">

                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>

                <th>序号</th>
                <th>时间</th>
                <th>单位</th>
                <th>项目</th>
                <th>项目金额</th>
                <th>介绍人</th>
                <th>业务</th>
                <th>派单业务</th>
                <th>责任人</th>
                <th>跟单</th>
                <th>设计师</th>
                <th>程序员</th>
                <th>编辑</th>
                <th>运营</th>
            </tr>
            </thead>
            <tbody>


            <? for($i=0;$i<count($case_list2);$i++){?>
                <tr>
                    <td><?echo $i+1?></td>
                    <td><?echo substr($case_list2[$i]['paydate'],0,10)?></td>
                    <td> <a href="/controller/extender/unit/view/detail-statistic.php?&nid=<?echo $case_list2[$i]['unit']?>&nav-itemed=unit" target="_blank"><?echo $unit_name_list2[$case_list2[$i]['unit']]?> </a> </td>
                    <td><a href="/controller/extender/case/view/detail-edit.php?&nid=<?echo $case_list2[$i]['nid']?>&nav-itemed=case"  target="_blank"><?echo $case_list2[$i]['name']?></a> </td>
                    <td><?echo $case_list2[$i]['sum']?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['agent']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];
                            $sum_agent2[]=$case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['sales']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];
                            $sum_sales2[]=$case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['dist_sales']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['dist_sales_bonus'];
                            $sum_dist_sales2[]=$case_bonus2[$case_list2[$i]['nid']]['dist_sales_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['respon']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];
                            $sum_respon2[]=$case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['service']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['service_bonus'];
                            $sum_service2[]=$case_bonus2[$case_list2[$i]['nid']]['service_bonus'];}?></td></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['designer']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];
                            $sum_designer2[]=$case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['programer']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];
                            $sum_programer2[]=$case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['editor']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];
                            $sum_editor2[]=$case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];}?></td>
                    <td><?if($case_bonus2[$case_list2[$i]['nid']]['operator']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['operator_bonus'];
                            $sum_operator2[]=$case_bonus2[$case_list2[$i]['nid']]['operator'];}?></td>


                </tr>
                <?;}?>

        

            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td><?echo array_sum($sum_agent2);?> </td>
                <td><?echo array_sum($sum_sales2);?> </td>
                <td><?echo array_sum($sum_dist_sales2);?> </td>
                <td><?echo array_sum($sum_respon2);?> </td>
                <td><?echo array_sum($sum_service2);?> </td>
                <td><?echo array_sum($sum_designer2);?> </td>
                <td><?echo array_sum($sum_programer2);?> </td>
                <td><?echo array_sum($sum_editor2);?> </td>
                <td><?echo array_sum($sum_operator2);?> </td>
            </tr>
            <tr>
                <td colspan="14" style="text-align: center">合计<?echo array_sum($sum_agent2)+array_sum($sum_sales2)+array_sum($sum_dist_sales2)+array_sum($sum_respon2)+array_sum($sum_service2)+array_sum($sum_designer2)+array_sum($sum_programer2)+array_sum($sum_editor2);?></td>
            </tr>


            </tbody>
        </table>
    </div>
</div>











<?
//上两个月的
$last_2month=date('Y-m',strtotime('midnight first day of -2 month'));


?>
<fieldset class="layui-elem-field layui-field-title">
    <legend> 个人绩效：<? echo $last_2month?> </legend>
</fieldset>
<?



$case_list3 = select_lines_all_items($table_Prefix . "case", "nid desc", "
(agent     ='" . $workerid . "' or
respon    ='" . $workerid . "' or
sales     ='" . $workerid . "' or
dist_sales     ='" . $workerid . "' or
service   ='" . $workerid . "' or
designer  ='" . $workerid . "' or
programer ='" . $workerid . "' or
operator ='" . $workerid . "' or
editor    ='" . $workerid . "') and count_date like '".$last_2month."%' ", "");


$case_id_list3=transform_2darray_in_1darray_number_as_key($case_list3,"nid");

$case_id_list_srt3=implode(",", $case_id_list3);

$bonus_list3 = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt3.")", "0");

foreach($bonus_list3 as $k => $v)
{
    $case_bonus3[$v['caseid']]=$v;
}




//获取本页用到的单位的名字
$unit_nid_list3=transform_2darray_in_1darray_with_new_key($case_list3,"nid","unit");
$unit_nid_list_str3=implode("','",$unit_nid_list3);
$unit_list3=select_lines_all_items($table_Prefix."unit","","nid in ('".$unit_nid_list_str3."')","");
$unit_name_list3=transform_2darray_in_1darray_with_new_key($unit_list3,"nid","name");

?>


<div class=" statistics-box layui-form">


    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="60">
                <col width="120">

                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>

                <th>序号</th>
                <th>时间</th>
                <th>单位</th>
                <th>项目</th>
                <th>项目金额</th>
                <th>介绍人</th>
                <th>业务</th>
                <th>派单业务</th>
                <th>责任人</th>
                <th>跟单</th>
                <th>设计师</th>
                <th>程序员</th>
                <th>编辑</th>
                <th>运营</th>
            </tr>
            </thead>
            <tbody>


            <? for($i=0;$i<count($case_list3);$i++){?>
                <tr>
                    <td><?echo $i+1?></td>
                    <td><?echo substr($case_list3[$i]['paydate'],0,10)?></td>
                    <td> <a href="/controller/extender/unit/view/detail-statistic.php?&nid=<?echo $case_list3[$i]['unit']?>&nav-itemed=unit" target="_blank"><?echo $unit_name_list3[$case_list3[$i]['unit']]?> </a> </td>
                    <td><a href="/controller/extender/case/view/detail-edit.php?&nid=<?echo $case_list3[$i]['nid']?>&nav-itemed=case"  target="_blank"><?echo $case_list3[$i]['name']?></a> </td>
                    <td><?echo $case_list3[$i]['sum']?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['agent']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['agent_bonus'];
                            $sum_agent3[]=$case_bonus3[$case_list3[$i]['nid']]['agent_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['sales']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['sales_bonus'];
                            $sum_sales3[]=$case_bonus3[$case_list3[$i]['nid']]['sales_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['dist_sales']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['dist_sales_bonus'];
                            $sum_dist_sales3[]=$case_bonus3[$case_list3[$i]['nid']]['dist_sales_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['respon']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['respon_bonus'];
                            $sum_respon3[]=$case_bonus3[$case_list3[$i]['nid']]['respon_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['service']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['service_bonus'];
                            $sum_service3[]=$case_bonus3[$case_list3[$i]['nid']]['service_bonus'];}?></td></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['designer']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['designer_bonus'];
                            $sum_designer3[]=$case_bonus3[$case_list3[$i]['nid']]['designer_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['programer']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['programer_bonus'];
                            $sum_programer3[]=$case_bonus3[$case_list3[$i]['nid']]['programer_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['editor']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['editor_bonus'];
                            $sum_editor3[]=$case_bonus3[$case_list3[$i]['nid']]['editor_bonus'];}?></td>
                    <td><?if($case_bonus3[$case_list3[$i]['nid']]['operator']==$workerid){echo $case_bonus3[$case_list3[$i]['nid']]['operator_bonus'];
                            $sum_operator3[]=$case_bonus3[$case_list3[$i]['nid']]['operator'];}?></td>

                </tr>
                <?;}?>



            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td><?echo array_sum($sum_agent3);?> </td>
                <td><?echo array_sum($sum_sales3);?> </td>
                <td><?echo array_sum($sum_dist_sales3);?> </td>
                <td><?echo array_sum($sum_respon3);?> </td>
                <td><?echo array_sum($sum_service3);?> </td>
                <td><?echo array_sum($sum_designer3);?> </td>
                <td><?echo array_sum($sum_programer3);?> </td>
                <td><?echo array_sum($sum_editor3);?> </td>
                <td><?echo array_sum($sum_operator3);?> </td>
            </tr>
            <tr>
                <td colspan="14" style="text-align: center">合计<?echo array_sum($sum_agent3)+array_sum($sum_sales3)+array_sum($sum_dist_sales3)+array_sum($sum_respon3)+array_sum($sum_service3)+array_sum($sum_designer3)+array_sum($sum_programer3)+array_sum($sum_editor3);?></td>
            </tr>


            </tbody>
        </table>
    </div>
</div>












